package cn.itcast.nems.common.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * author liyong
 * create: 2024-04-09 09:24:46
 **/
@Service
public class TransactionTestService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    private final AfterTransactionCommitExecutor executor;

    public TransactionTestService(AfterTransactionCommitExecutor executor) {
        this.executor = executor;
    }

    @Transactional
    public void transactionMethod() {
        logger.info("执行事务方法");
        this.executor.addRunnable(() -> {
            logger.info("执行事务提交后的逻辑");
        });
    }
}
